/**
 * Created by Administrator on 2017/3/11.
 *
 * 线程死锁，两个方法相互持有对方的锁 （一个method中两个syn）
 *
 */
public class DeathLock {
    private String A = "a";
    private String B = "b";


    public void method1()throws Exception{
        synchronized (A){
            System.out.println("-----------method1-A-----------");
            Thread.sleep(10000);
            synchronized (B){
                System.out.println("-----------method1-B-----------");
            }
        }
    }


    public void method2()throws Exception{
        synchronized (B){
            System.out.println("-----------method2-B-----------");
            Thread.sleep(10000);
            synchronized (A){
                System.out.println("-----------method2-A-----------");
            }
        }
    }

    public static void main(String [] args)throws Exception{

        final DeathLock lock =new DeathLock();
        new Thread(()-> {
            try {
                lock.method1();
            }catch (Exception e){
                e.printStackTrace();
            }
        }).start();
        lock.method2();


    }
}
